package models

func UpdateEmpData(emp * EmployeeInfo) error {
	_,err:=updateEmp.Exec(emp.Name,emp.Status,emp.ArriveDate,emp.Job,emp.Position,emp.Id)
	return  err
}

func TransEmpData(emp * EmployeeInfo,trans *TransferInfo)error  {
	res, err := Db.Query("SELECT DepartmentID FROM worker_transfer_informations.employees WHERE WorkerID=?",emp.Id)
	if err!=nil{
		return err
	}
	oldDepartmentId:=-1;
	res.Next()
	err=res.Scan(&oldDepartmentId)
	if err != nil {
		return err
	}
	_,err=transEmpQuery.Exec(emp.Name,emp.Status,emp.ArriveDate,emp.Job,emp.Position,emp.DepartmentID,emp.Id)
	if err!=nil{
		return err
	}
	trans.WorkId=trans.Id
	trans.TransDate=emp.ArriveDate
	trans.OutDep=oldDepartmentId
	trans.InDep=emp.DepartmentID
	_,err=createTransInfo.Exec(trans.WorkId,trans.TransDate,trans.InDep,trans.OutDep,trans.Why)
	return err

}

